import { useDetail, useList } from "@/hooks";
import { getUserInfoUrl } from "@/command/apiTool";
import { getAction } from "@/command/netTool";
import * as vant from "vant";
const { showFailToast, showSuccessToast } = vant;

export const useRequest = () => {
  // 小户查询我的结队大户信息
  const [myTeamInfo] = useDetail(
    getUserInfoUrl({
      dh: "",
      xh: "/api/H5/richCourse/small/myTeamInfo",
    }),
    {
      userId: "",
      name: "",
      address: "",
      distance: "",
      entityComment: "",
      logoUrl: "",
      phone: "",
      title: "",
      workName: "",
      workDay: "",
      workPrice: "",
      userApplyVOList: [],
    }
  );

  // 农基课堂-查询所有课堂
  const [classroomList] = useDetail(
    getUserInfoUrl({
      dh: "/api/H5/richCourse/large/listData",
      xh: "/api/H5/richCourse/small/listData",
    }),
    []
  );

  // 农技专家
  const [queryExpertList] = useDetail(
    getUserInfoUrl({
      dh: "/api/H5/richCourse/large/queryExpert",
      xh: "/api/H5/richCourse/small/queryExpert",
    }),
    []
  );

  // 线下培训
  const [trainList, trainListControl] = useDetail(
    getUserInfoUrl({
      dh: "/api/H5/richCourse/large/train",
      xh: "/api/H5/richCourse/small/train",
    }),
    []
  );

  const btnAction = (params: any) => {
    getAction(
      getUserInfoUrl({
        dh: "/api/H5/richCourse/large/join",
        xh: "/api/H5/richCourse/small/join",
      }).url,
      { ...params },
      { isResolve: true }
    ).then((e) => {
      console.log("eee", e);
      showSuccessToast(e.data);
      // 刷新接口
      trainListControl.refresh();
    });
  };
  return {
    classroomList,
    queryExpertList,
    trainList,
    btnAction,
    myTeamInfo,
  };
};
